using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

using DataTransferObject;
using Business;



namespace Presentation.UserControlls
{
    public partial class UC_TheLoaiSach : UserControl
    {
        clsTheLoaiDTO theloaiDTO = new clsTheLoaiDTO();
        clsTheLoaiBUS theloaiBUS = new clsTheLoaiBUS();
        clsThuKhoBUS ThuKhoBUS = new clsThuKhoBUS();

        DataTable tbl = new DataTable();
        int tongcong;
        string theloai;


        public UC_TheLoaiSach()
        {
            InitializeComponent();
        }

        private void buttonX2_Click(object sender, EventArgs e)
        {
            DialogResult dlg = new DialogResult();
            dlg = DevComponents.DotNetBar.MessageBoxEx.Show("Bạn có muốn thoát không ?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            if (dlg == DialogResult.Yes)
            {
                this.ParentForm.Close();

            }
        }

        private void UC_TheLoaiSach_Load(object sender, EventArgs e)
        {
            tbl = theloaiBUS.DanhSachTheLoai();
            cbotheloai.DisplayMember = "TenTL";
            cbotheloai.ValueMember = "MaTL";
            cbotheloai.DataSource = tbl;
        }

        private void cbotheloai_SelectedIndexChanged(object sender, EventArgs e)
        {
            theloai = cbotheloai.SelectedValue.ToString();
            theloaiDTO .MaTL =theloai.Trim ();

            tbl = ThuKhoBUS.ThuKoThongKeTheLoaiSachTrongThuVien(theloaiDTO);
            tongcong = 0;
            HienThiListView(tbl);
            lbltongcong.Text = Convert.ToString(tongcong);
        }

        private void HienThiListView(DataTable tbl)
        {
            ListViewItem lvwitem = new ListViewItem();
            lvwthongketheotheloai.Items.Clear();
            int i = 1;
            foreach (DataRow dr in tbl.Rows)
            {
                tongcong = tongcong + 1;
                lvwitem = new ListViewItem();
                lvwitem.Text = Convert.ToString(i++);
                lvwitem.SubItems.Add(dr["DKCB"].ToString());
                lvwitem.SubItems.Add(dr["TenTuaSach"].ToString());
                //lvwitem.SubItems.Add(dr["MaHong"].ToString());
                //lvwitem.SubItems.Add(dr["TenHong"].ToString());
                lvwitem.SubItems.Add(dr["Gia"].ToString());
                lvwitem.SubItems.Add(dr["TenTL"].ToString());

                lvwthongketheotheloai.Items.Add(lvwitem);
            }


        }

        private void buttonX1_Click(object sender, EventArgs e)
        {
            FromInAn.FrmThongKeTheoTheLoai Tktheloai = new Presentation.FromInAn.FrmThongKeTheoTheLoai();
            Tktheloai.Show();
        }
    }
}
